home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _6C5F263CF14F488884592093FD1BEBC3 < prev    next >
Text File  |  2005-02-17  |  2KB  |  101 lines

  1. //submerged object vertex shader:
  2. //ripples the vertices of things underwater
  3. //2 directional lights and ambient light also applied
  4. //must be used with submerged.psh
  5. //Luke Lenhart
  6. //(C)2004-2005 Digipen Institute of Technology
  7.  
  8. //NOTE: only vertices with a z value < -2 will be affected by this effect
  9.  
  10.  
  11. //combined view,projection transform
  12. float4x4 matViewProj;
  13. //world transform
  14. float4x4 matWorld;
  15. //rotational transform from world
  16. float4x4 matWorldRotation;
  17.  
  18. //2 directional lights
  19. float4 l1Direction;
  20. float4 l1Color;
  21.  
  22. float4 l2Direction;
  23. float4 l2Color;
  24.  
  25. //ambient light
  26. float4 lAmbient;
  27.  
  28. //alpha modifier for mesh
  29. float alphaMod;
  30.  
  31. //camera position in world space
  32. float4 cameraPos;
  33.  
  34. //current time (in seconds) since whenever
  35. float curTime;
  36.  
  37. //multiplier for how much underwater wavery effect gets applied
  38. float waveMod;
  39.  
  40. //shader input
  41. struct VS_INPUT
  42. {
  43.     float4 Pos : POSITION;
  44.     float4 Normal : NORMAL;
  45.     float2 Tex0 : TEXCOORD0;
  46. };
  47.  
  48. //shader output
  49. struct VS_OUTPUT
  50. {
  51.     float4 Pos : POSITION;
  52.     float4 Color : COLOR;
  53.     float2 Tex0 : TEXCOORD0;
  54. };
  55.  
  56. //shader code
  57. VS_OUTPUT VShader(VS_INPUT In)
  58. {
  59.     VS_OUTPUT Out;
  60.     
  61.     //calc colors from directional lights
  62.     float4 norm=mul(matWorldRotation,-In.Normal);
  63.     float4 l1Contrib=dot(norm,l1Direction)*l1Color;
  64.     l1Contrib=saturate(l1Contrib);
  65.     
  66.     float4 l2Contrib=dot(norm,l2Direction)*l2Color;
  67.     l2Contrib=saturate(l2Contrib);
  68.     
  69.     Out.Color=l1Contrib + l2Contrib + lAmbient;
  70.     
  71.     //calc transformed position and copy texture coord
  72.     Out.Tex0=In.Tex0;
  73.     float4 worldPos=mul(matWorld,In.Pos);
  74.     
  75.     //do ripple effect if z is less than -2
  76.     if (worldPos.z<-2.0f) //underwater
  77.     {    
  78.         //use 1/distance from camera is a base offset distance
  79.         float invCamDist=1.0f/distance(cameraPos,worldPos);
  80.         float2 theta=In.Pos.xy+curTime;
  81.         theta.y+=3.14;
  82.         worldPos.xy+=waveMod*sqrt(invCamDist)*worldPos.z*2.5f*sin(theta);
  83.         
  84.         //less alpha with less z
  85.         Out.Color.a=1.0f+worldPos.z/9.0f;
  86.     }
  87.     else //above water
  88.     {
  89.         Out.Color.a=1.0f;
  90.     }
  91.     
  92.     //do view/project transform
  93.     Out.Pos=mul(matViewProj,worldPos);
  94.     
  95.     //modify alpha
  96.     Out.Color.a*=alphaMod;
  97.  
  98.     //spit out the results
  99.     return Out;
  100. }
  101.